package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.TrackInfoQuery;
import com.atguigu.tingshu.vo.album.TrackListVo;
import com.atguigu.tingshu.vo.album.TrackStatVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface TrackInfoMapper extends BaseMapper<TrackInfo> {


    /**
     * 获取当前用户声音分页列表
     * @param page1 分页信息
     * @param trackInfoQuery  条件
     * @return
     */
    Page<TrackListVo> selectUserTrackPage(@Param("page1") Page page1,@Param("vo") TrackInfoQuery trackInfoQuery);

    /**
     * 删除声音信息后维护声音表的 order_num列
     * @param albumId
     * @param orderNum
     */
    void updateOrderNum(@Param("albumId") Long albumId, @Param("orderNum") Integer orderNum);

    /**
     * 根据声音ID，查询声音统计信息
     * @param trackId
     * @return
     */
    @Select("select\n" +
            "    track_id,\n" +
            "    max(if(stat_type='0701', stat_num, 0)) playStatNum,\n" +
            "    max(if(stat_type='0702', stat_num, 0)) collectStatNum,\n" +
            "    max(if(stat_type='0703', stat_num, 0)) praiseStatNum,\n" +
            "    max(if(stat_type='0704', stat_num, 0)) commentStatNum\n" +
            "    from track_stat where track_id = #{trackId} and is_deleted=0\n" +
            "group by track_id")
    TrackStatVo getTrackStatVo(@Param("trackId") Long trackId);

    @Select("select *\n" +
            "    from track_info  where order_num >#{orderNum} and album_id = #{albumId} and is_deleted='0'\n")
    List<TrackInfo> selectXuYaoBuy(@Param("albumId") Long albumId, @Param("orderNum") Integer orderNum);
}
